package oceanpayment

import (
    "fmt"
	//"errors"
	//"strings"
	"encoding/xml"
	"thirdpaysdk/utils/mapstruct"
	//"github.com/astaxie/beego"
)

/*
<?xml version="1.0" encoding="UTF-8"?>
<response><response_type>1</response_type><account>191208</account><terminal>19120801</terminal><signValue>DEE4C6A6A12B17D02FB882D09EF2EBFD6FCF3150000F3E31BAC7E69401724D3B</signValue><methods>WX</methods><order_number>323538628007432192</order_number><card_country></card_country><order_currency>CNY</order_currency><order_amount>0.01</order_amount><order_notes></order_notes><card_number></card_number><card_type></card_type><payment_country>GB</payment_country><payment_id>190307143513492120870</payment_id><payment_authType>0</payment_authType><payment_status>-1</payment_status><payment_details>Pending</payment_details><payment_solutions></payment_solutions><payment_risk></payment_risk><customer_id></customer_id><subscribe></subscribe><pay_bankCode></pay_bankCode><pay_barCode></pay_barCode><payment_bankInfo>{"timeStamp":"1551940513","signType":"MD5","package":"prepay_id=wx07143513795968c19dd1a9df2892423447","nonceStr":"1551940513564","paySign":"8DAB45F2F2BD03CC4B8C397B6FBEA310"}</payment_bankInfo></response>

*/
type OceanPayMsg struct {
	ResponseType     string `xml:"response_type"`
	Account          string `xml:"account"`
	Terminal         string `xml:"terminal"`
	SignValue        string `xml:"signValue"`
	Methods          string `xml:"methods"`
	OrderNumber      string `xml:"order_number"`
	OrderCurrency    string `xml:"order_currency"`
	OrderAmount      string `xml:"order_amount"`
	OrderNotes       string `xml:"order_notes"`
	CardNumber       string `xml:"card_number"`
	CardType         string `xml:"card_type"`
	PaymentCountry   string `xml:"payment_country"`
	PaymentId        string `xml:"payment_id"`
	PaymentAuthType  string `xml:"payment_authType"`
	PaymentStatus    string `xml:"payment_status"`
	PaymentDetails   string `xml:"payment_details"`
	PaymentSolutions string `xml:"payment_solutions"`
	PaymentRisk      string `xml:"payment_risk"`
}

func OceanPayMsgNotify(body []byte) (map[string]string, error){
	var response OceanPayMsg
	err := xml.Unmarshal(body, &response)
	if err != nil {
		return map[string]string{}, err
	}
	rspMap :=  mapstruct.Struct2Map(response, "xml")
	reqMap := make(map[string]string)
	for k, v := range rspMap {
		reqMap[k] = fmt.Sprintf("%v", v)
	}
	return reqMap, nil
}
